package com.iflyun.rabbitmq.main;

import java.security.Security;
import java.util.Date;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;



public class TestMain {

	/** 
	
	* @Title: main 
	
	* @Description: TODO(这里用一句话描述这个方法的作用) 
	
	* @author wenquxing
	
	* @date 2016年7月1日 下午2:47:40
	
	* @param @param args
	* @param @throws AddressException
	* @param @throws MessagingException 
	
	* @return void 
	
	* @throws 
	
	*/ 
	public static void main(String[] args) throws AddressException, MessagingException {
		// TODO Auto-generated method stub
	        String SEND_USER = "yanzhengwei667@163.com";
	        String SEND_UNAME = "yanzhengwei667";
	        String SEND_PWD = "19930912yan";
	        String VALUE_SMTP = "smtp.163.com";
	        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
	        //final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
	        // Get a Properties object
	        Properties props = System.getProperties();
	        // props.setProperty("mail.smtp.host", "smtp.gmail.com");
	        props.setProperty("mail.smtp.host", "smtp.163.com");
	        //props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
	        //props.setProperty("mail.smtp.socketFactory.fallback", "false");
	         props.setProperty("mail.smtp.port", "25");
	        //props.setProperty("mail.smtp.port", "587");
	        //props.setProperty("mail.smtp.socketFactory.port", "25");
	        //props.setProperty("mail.smtp.socketFactory.port", "587");
	        props.put("mail.smtp.auth", "true");
	        final String username = "yanzhengwei667";
	        final String password = "19930912yan";
	        Session session = Session.getDefaultInstance(props,
	                new Authenticator() {
	                    protected PasswordAuthentication getPasswordAuthentication() {
	                        return new PasswordAuthentication(username, password);
	                    }
	                });
	 
	        // -- Create a new message --
	        session.setDebug(true);
	        Message msg = new MimeMessage(session);
	 
	        // -- Set the FROM and TO fields --
	        msg.setFrom(new InternetAddress(username + "@163.com"));
	        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
	                "wenquxing@iflyun.com,941911337@qq.com", false));
	        msg.setSubject("RabbitMQ监测");
	        msg.setText("生产 环境 MQ 172.16.7.138 MQ正常");
	        msg.setSentDate(new Date());
	        Transport transport = session.getTransport("smtp");
	        // smtp验证，就是你用来发邮件的邮箱用户名密码
	        transport.connect(VALUE_SMTP, SEND_UNAME, SEND_PWD);
	        // 发送
	        transport.sendMessage(msg, msg.getAllRecipients());
	        Transport.send(msg);
	        transport.close();
	 
	        System.out.println("Message sent.");
	    }

	

}
